home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Cinema - PTGate (imagem pequena).ifs < prev    next >
Encoding:
Text File  |  2004-06-07  |  8.1 KB  |  284 lines

  1. // GETINFO SCRIPTING
  2. // http://cinema.ptgate.pt/(imagem pequena)
  3. // Script feito pelo O Guardiπo versπo 1.0 Alpha 2
  4. // 29-05-2004
  5.  
  6.  
  7. (***************************************************
  8.  *  For use with Ant Movie Catalog 3.4.0           *
  9.  *  www.antp.be/software/moviecatalog              *
  10.  *                                                 *
  11.  *  The source code of the script can be used in   *
  12.  *  another program only if full credits to        *
  13.  *  script author and a link to Ant Movie Catalog  *
  14.  *  website are given in the About box or in       *
  15.  *  the documentation of the program               *
  16.  *                                                 *
  17.  *  Please dont remove credits                     *
  18.  *  Reportem os erros para bruno_mga@hotmail.com   *
  19.  ***************************************************)
  20. program PTGate;
  21. const
  22.   BaseAddress = 'http://cinema.ptgate.pt/';
  23.   ManualPictureSelect = True;
  24.   ExternalPictures = False;
  25.   DescriptionToImport = 2;
  26. var
  27.   MovieName: string;
  28.   MovieURL: string;
  29. function HTMLRemove(Value: String): String;
  30. begin
  31.   HTMLDecode(Value);
  32.   HTMLRemoveTags(Value);
  33.   Value := Trim(Value);
  34.   result := Value;
  35. end;
  36.  
  37. procedure AnalyzeFilmPage(Address: String);
  38. var
  39.   Page : TStringList;
  40.   Line, Value : string;
  41.   LineNr, BeginPos, EndPos: Integer;
  42.   AllTitles: TStringList;
  43.   url_imdb:string;
  44. begin
  45.   Page := TStringList.Create;
  46.   Address:='http://cinema.ptgate.pt/filme.php?code='+Address;
  47.   Page.Text := GetPage(Address);
  48.   SetField(fieldURL, Address);
  49.  
  50.  
  51.  
  52.   //obter nome do filme
  53.   LineNr := FindLine('<td bgcolor=#6496D2 width=360 colspan=2><table border=0 cellspacing=0 cellpadding=0><td width=5><br></td><td><font color=white><b class=ttl>', Page, 0);
  54.   if LineNr<>-1 then
  55.   begin
  56.     Value := Page.GetString(LineNr+1);
  57.     BeginPos := pos('</b><br><', value)+9;
  58.     value:=copy(value,4,BeginPos);
  59.  
  60.    AllTitles := TStringList.Create;
  61.    AllTitles.Add(HTMLRemove(value));
  62.  
  63.     //por o the no principio do nome
  64.     if pos(', The</b><br>',value) <>0 then
  65.     begin
  66.       url_imdb:=HTMLRemove(value);
  67.       value:= StringReplace(value, ', The</b><br>', '');
  68.       value:='The '+value;
  69.       value:=HTMLRemove(value);
  70.       AllTitles.Add(value);
  71.     end;
  72.  
  73.     value:=HTMLRemove(value);
  74.     SetField(fieldOriginalTitle, Value);
  75.   end;
  76.  
  77.   //imagem
  78.   Value := Page.GetString(LineNr-1);
  79.   Value:= StringReplace(value, '            "></td>', '');
  80.   Value:= StringReplace(value, '            ', '');
  81.   Value:='http://cinema.ptgate.pt/'+value;
  82.   GetPicture(Value, False);
  83.  
  84.   //obter nome traduzido
  85.   Value := Page.GetString(LineNr+1);
  86.   BeginPos := pos('><i class=subttl>', value)+17;
  87.   EndPos:=Pos('<br></i></td><td width=5><br></',value);
  88.   value:=copy(value,BeginPos,EndPos-BeginPos);
  89.   value:=Copy(value,1,endpos);
  90.   value:=HTMLRemove(value);
  91.   SetField(fieldTranslatedTitle, Value);
  92.  
  93.  
  94.   //Realizador
  95.   LineNr := FindLine('<!-- real -->', Page, 0);
  96.   if LineNr<>-1 then
  97.   begin
  98.     Value := Page.GetString(LineNr+3);
  99.     BeginPos:=Pos('>',value)+1;
  100.     EndPos:=Pos('</a>',value);
  101.     value:=copy(value,BeginPos,EndPos-BeginPos);
  102.     value:=HTMLRemove(value);
  103.     SetField(fieldDirector, Value);
  104.   end;
  105.  
  106.   //actores
  107.   LineNr := FindLine('><b>IntΘrpretes: </b>', Page, 0);
  108.   if LineNr<>-1 then
  109.   begin
  110.     Value := Page.GetString(LineNr+1);
  111.     value:= StringReplace(value,'            </font></td>' , '');
  112.     value:= StringReplace(value,'            ' , '');
  113.     value:=HTMLRemove(value);
  114.     SetField(fieldActors, Value);
  115.   end;
  116.  
  117.   //ano
  118.   LineNr := FindLine('<!-- ano -->', Page, 0);
  119.   if LineNr<>-1 then
  120.   begin
  121.     Value := Page.GetString(LineNr+1);
  122.     value:=HTMLRemove(value);
  123.     BeginPos:=pos('Ano:',value);
  124.     Value:=Copy(value,beginPos+6,length(value));
  125.     SetField(fieldYear, value);
  126.   end;
  127.   url_imdb:=url_imdb+' ('+Value+')';
  128.  
  129.   //genero
  130.   LineNr := FindLine('<!-- gene -->', Page, 0);
  131.   if LineNr<>-1 then
  132.   begin
  133.     Value := Page.GetString(LineNr+1);
  134.     BeginPos:=Pos('<font size=2 face=verdana,arial>',Value);
  135.     EndPos:=Pos('</font></td>',Value);
  136.     value:=Copy(value,BeginPos,EndPos-BeginPos);
  137.     value:=HTMLRemove(value);
  138.     SetField(fieldCategory, value);
  139.   end;
  140.  
  141.   //paφs
  142.   LineNr := FindLine('<!-- pais -->', Page, 0);
  143.   if LineNr<>-1 then
  144.   begin
  145.     Value:= Page.GetString(LineNr+1);
  146.     BeginPos:=Pos('<font size=2 face=verdana,arial>',Value);
  147.     EndPos:=Pos('</font></td>',Value);
  148.     value:=Copy(value,BeginPos,EndPos-BeginPos);
  149.     value:=HTMLRemove(value);
  150.    SetField(fieldCountry, value);
  151.   end;
  152.  
  153.   //descriτπo
  154.   LineNr := FindLine('<!-- wall -->', Page, 0);
  155.   Value:= Page.GetString(LineNr+1);
  156.   if (LineNr<>-1) and (pos('<b>Sinopse</b><br>',value)<>0)  then
  157.   begin
  158.     Value:= Page.GetString(LineNr+2);
  159.     EndPos:=Pos('<br><br></font>',value);
  160.     Value:=Copy(Value,1,EndPos);
  161.     Value:=HTMLRemove(value);
  162.     SetField(fieldDescription, value);
  163.   end;
  164.  
  165.   url_imdb:=AllTitles.GetString(0)+' '+url_imdb;
  166.  
  167.   //imdb
  168.   url_imdb:= StringReplace(url_imdb, ' ', '+');
  169.   url_imdb:='http://us.imdb.com/Title?'+url_imdb;
  170.   Page.Text := GetPage(url_imdb);
  171.  
  172.   // Length
  173.   LineNr := FindLine('Runtime:', Page, 0);
  174.   if LineNr > -1 then
  175.   begin
  176.     Line := Page.GetString(LineNr + 1);
  177.     EndPos := pos(' min', Line);
  178.     if EndPos = 0 then
  179.       EndPos := pos('  /', Line);
  180.     if EndPos = 0 then
  181.       EndPos := Length(Line);
  182.     if Pos(':', Line) < EndPos then
  183.       BeginPos := Pos(':', Line) + 1
  184.     else
  185.       BeginPos := 1;
  186.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  187.     SetField(fieldLength, Value);
  188.   end;
  189.   
  190.     // Rating
  191.   LineNr := FindLine('User Rating:', Page, 0);
  192.   if LineNr > -1 then
  193.   begin
  194.     Line := Page.GetString(LineNr + 4);
  195.     if Pos('/10', Line) > 0 then
  196.     begin
  197.       BeginPos := pos('<b>', Line) + 3;
  198.       Value := IntToStr(Round(StrToInt(StrGet(Line, BeginPos), 0) + (StrToInt(StrGet(Line, BeginPos + 2), 0) / 10)));
  199.       SetField(fieldRating, Value);
  200.     end;
  201.   end;
  202.  
  203.     LineNr := FindLine('<img border="0" alt="cover"', Page, 0);
  204.   if LineNr > -1 then
  205.   begin
  206.     Line := Page.GetString(LineNr);
  207.     BeginPos := pos('src="', Line) + 4;
  208.     Delete(Line, 1, BeginPos);
  209.     EndPos := pos('"', Line);
  210.     Value := copy(Line, 1, EndPos - 1);
  211.     GetPicture(Value, False); // False = do not store picture externally ; store it in the catalog file
  212.   end;
  213. end;
  214.  
  215.  
  216.  
  217.  
  218.  
  219. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  220. var
  221.   i: Integer;
  222. begin
  223.   result := -1;
  224.   if StartAt < 0 then
  225.     StartAt := 0;
  226.   for i := StartAt to List.Count-1 do
  227.     if Pos(Pattern, List.GetString(i)) <> 0 then
  228.     begin
  229.       result := i;
  230.       Break;
  231.     end;
  232. end;
  233.  
  234. procedure AnalyzePage(Address: string);
  235. var
  236.   Page: TStringList;
  237.   LineNr, StartPos, EndPos: Integer;
  238.   Line: string;
  239.   x:integer;
  240.   MovieAddress, findMovieName,linedown : string;
  241.   guardar,url, nome_filme:string;
  242. begin
  243.   PickTreeClear;
  244.   Page := TStringList.Create;
  245.   Page.Text := GetPage(Address);
  246.  
  247.   if (pos('Nπo foram encontrados filmes ou pessoas que satisfaτam a sua pesquisa.', Page.Text)<>-1) then   //se existe
  248.   begin
  249.       LineNr := FindLine('filme.php?code=', Page, LineNr);
  250.       Line := Page.GetString(LineNr);
  251.     repeat
  252.         StartPos := pos('filme.php?code=', Line)+15;
  253.         if StartPos=15 then break;
  254.  
  255.         guardar:=Copy(line,StartPos+1,9999);
  256.         line:=Copy(line,StartPos,9999);    
  257.         StartPos := pos('>',line)+1;
  258.         url:=(copy(line,1,StartPos-3));
  259.         EndPos := pos('</a>',line)-1;
  260.         line := copy(Line, StartPos, EndPos - StartPos+1);
  261.           nome_filme:=line;
  262.         PickTreeAdd(nome_filme, url);
  263.         line:=guardar;
  264.         
  265. until (nome_filme='');
  266.  
  267.     if PickTreeExec(Address) then begin
  268.       AnalyzeFilmPage(Address);
  269.     end;
  270.     Page.Free;
  271.   end;
  272.   DisplayResults;
  273. end;
  274. begin
  275.   PickListClear;
  276.   MovieName := GetField(fieldOriginalTitle);
  277.   if Input('Importar do cinema.ptgate.pt', 'Escreva o nome do filme:', MovieName) then begin
  278.   //espaτo nπo sπo permitidos
  279.   MovieName := StringReplace(MovieName, ' ', '%20');
  280.   AnalyzePage('http://cinema.ptgate.pt/pesquisa.php?tx='+MovieName);
  281.   end;
  282. end.
  283.  
  284.